/**
 * Validiert die Event-Postleitzahl.
 * 
 * @author Michael Serajnik
 */

package at.fhj.itm10.ticketmaster.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator(value = "EventZipValidator")
public class EventZipValidator implements Validator {

	public void validate(FacesContext context, UIComponent component, Object value)
			throws ValidatorException {
		
		String eventZip = (String) value;
		String regEx = "^\\d+$";
		
		if(eventZip.length() == 0 || eventZip.length() < 4 || eventZip.length() > 6 || eventZip.matches(regEx) == false) {
			throw new ValidatorException(new FacesMessage("Bitte gib eine gültige Postleitzahl mit maximal 6 Zeichen an."));
		}
		
	}

}